#ifndef CDEVICE_H
#define CDEVICE_H
#include <string>
#include <thread>
#include <mutex>
#include "log/Logger.h"
class CDevieStatus
{
public:
    //单例 
    static CDevieStatus* GetInstance();
    //初始化
    void init(void);
private:
    CDevieStatus();
    ~CDevieStatus();
    void Proc(void);
//通过获取/proc/stat (CPU)和/proc/meminfo(内存和硬盘)文件信息
//proc/meminfo文件结构  
//MemTotal:       515164 kB  
//MemFree:         15024 kB  
//Buffers:         13740 kB  
//Cached:         248824 kB  
//SwapCached:    960 kB  
//Active:         309980 kB  
//Inactive:       63420 kB  
typedef struct MEMPACKED         //定义一个mem occupy的结构体  
{  
    char name1[20];      //定义一个char类型的数组名name有20个元素
    unsigned long MemTotal;
    char name2[20];
    unsigned long MemFree;
    char name3[20];
    unsigned long Buffers;
    char name4[20];
    unsigned long Cached;
    char name5[20];
    unsigned long SwapCached;

    void dump(void)
    {
        LOG_INFO("**************** Device Status Info ***************");
        LOG_INFO("MemTotal     : " << MemTotal);
        LOG_INFO("MemFree      : " << MemFree);
        LOG_INFO("Buffers      : " << Buffers);
        LOG_INFO("Cached       : " << Cached);
        LOG_INFO("SwapCached   : " <<SwapCached);
        LOG_INFO("=============== Device Status Info ===============");
    }

}MEM_OCCUPY;  
//proc/stat 文件结构
//cpu  633666 46912 249878 176813696 782884 2859 19625 0  
//cpu0 633666 46912 249878 176813696 782884 2859 19625 0  
//intr 5812844  
//ctxt 265816063  
//btime 1455203832  
//processes 596625  
//procs_running 1  
//procs_blocked 0  
typedef struct CPUPACKED         //定义一个cpu occupy的结构体  
{  
    char name[20];      //定义一个char类型的数组名name有20个元素
    unsigned int user; //定义一个无符号的int类型的user
    unsigned int nice; //定义一个无符号的int类型的nice
    unsigned int system;//定义一个无符号的int类型的system
    unsigned int idle; //定义一个无符号的int类型的idle
    unsigned int lowait;
    unsigned int irq;
    unsigned int softirq;
    
}CPU_OCCUPY;

void  GetMemOccupy(MEM_OCCUPY *mem); //内存
void   GetCpuOccupy(CPU_OCCUPY *cpust); //cpu
void   CalCpuOccupy(CPU_OCCUPY *o, CPU_OCCUPY *n);
void  GetUsedTime(); //使用时间
private:
    static CDevieStatus *m_pInstance;
    std::thread *m_pThread;
    std::mutex m_PthreadMtx;
};

#endif